package net.minecraft.src;

public class RenderChalkDust {

	public void renderBlockUsingTexture(Block block, int i, int j, int k, int l)
	{
		overrideBlockTexture = l;
		renderBlockByRenderType(block, i, j, k);
		overrideBlockTexture = -1;
	}

	public boolean renderBlockByRenderType(Block block, int i, int j, int k)
	{
		int l = block.getRenderType();
		block.setBlockBoundsBasedOnState(blockAccess, i, j, k);
		if(l == 18)
		{
			return renderBlockChalkDust(block, i, j, k);
		}
		else
		{
			return false;
		}
	}
	
	public boolean renderBlockChalkDust(Block block, int i, int j, int k)
	{
	  	Tessellator tessellator = Tessellator.instance;
	  	int l = blockAccess.getBlockMetadata(i, j, k);
	  	int i1 = block.getBlockTextureFromSideAndMetadata(1, l);
	  	if(overrideBlockTexture >= 0)
	  	{
	  		i1 = overrideBlockTexture;
	  	}
	
	  	float r = 255;
	  	float g = 255;
	  	float b = 255;
	
	  	float f = block.getBlockBrightness(blockAccess, i, j, k);
	  	float f1 = (float)l / 15F;
	  	float f2 = f1 * 0.6F + 0.4F;
	  	if(l == 0)
	  	{
	  		f2 = 0.3F;
	  	}
	  	float f3 = f1 * f1 * 0.7F - 0.5F;
	  	float f4 = f1 * f1 * 0.6F - 0.7F;
	  	if(f3 < 0.0F)
	  	{
	  		f3 = 0.0F;
	  	}
	  	if(f4 < 0.0F)
	  	{
	  		f4 = 0.0F;
	  	}
//		tessellator.setColorOpaque_F(f * f2, f * f3, f * f4);
	  	tessellator.setColorOpaque_F(r, g, b);
	  	int j1 = (i1 & 0xf) << 4;
	  	int k1 = i1 & 0xf0;
	  	double d = (float)j1 / 256F;
	  	double d2 = ((float)j1 + 15.99F) / 256F;
	  	double d4 = (float)k1 / 256F;
	  	double d6 = ((float)k1 + 15.99F) / 256F;
	  	boolean flag = BlockChalkDust.isPowerProviderOrWire(blockAccess, i - 1, j, k, 1) || !blockAccess.isBlockNormalCube(i - 1, j, k) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i - 1, j - 1, k, -1);
	  	boolean flag1 = BlockChalkDust.isPowerProviderOrWire(blockAccess, i + 1, j, k, 3) || !blockAccess.isBlockNormalCube(i + 1, j, k) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i + 1, j - 1, k, -1);
	  	boolean flag2 = BlockChalkDust.isPowerProviderOrWire(blockAccess, i, j, k - 1, 2) || !blockAccess.isBlockNormalCube(i, j, k - 1) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i, j - 1, k - 1, -1);
	  	boolean flag3 = BlockChalkDust.isPowerProviderOrWire(blockAccess, i, j, k + 1, 0) || !blockAccess.isBlockNormalCube(i, j, k + 1) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i, j - 1, k + 1, -1);
	  	if(!blockAccess.isBlockNormalCube(i, j + 1, k))
	  	{
	  		if(blockAccess.isBlockNormalCube(i - 1, j, k) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i - 1, j + 1, k, -1))
	  		{
	  			flag = true;
	  		}
	  		if(blockAccess.isBlockNormalCube(i + 1, j, k) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i + 1, j + 1, k, -1))
	  		{
	  			flag1 = true;
	  		}
	  		if(blockAccess.isBlockNormalCube(i, j, k - 1) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i, j + 1, k - 1, -1))
	  		{
	  			flag2 = true;
	  		}
	  		if(blockAccess.isBlockNormalCube(i, j, k + 1) && BlockChalkDust.isPowerProviderOrWire(blockAccess, i, j + 1, k + 1, -1))
	  		{
	  			flag3 = true;
	  		}
	  	}
	  	float f5 = i + 0;
	  	float f6 = i + 1;
	  	float f7 = k + 0;
	  	float f8 = k + 1;
	  	byte byte0 = 0;
	  	if((flag || flag1) && !flag2 && !flag3)
	  	{
	  		byte0 = 1;
	  	}
	  	if((flag2 || flag3) && !flag1 && !flag)
	  	{
	  		byte0 = 2;
	  	}
	  	if(byte0 != 0)
	  	{
	  		d = (float)(j1 + 16) / 256F;
	  		d2 = ((float)(j1 + 16) + 15.99F) / 256F;
	  		d4 = (float)k1 / 256F;
	  		d6 = ((float)k1 + 15.99F) / 256F;
	  	}
	  	if(byte0 == 0)
	  	{
	  		if(flag1 || flag2 || flag3 || flag)
	  		{
	  			if(!flag)
	  			{
	  				f5 += 0.3125F;
	  			}
	  			if(!flag)
	  			{
	  				d += 0.01953125D;
	  			}
	  			if(!flag1)
	  			{
	  				f6 -= 0.3125F;
	  			}
	  			if(!flag1)
	  			{
	  				d2 -= 0.01953125D;
	  			}
	  			if(!flag2)
	  			{
	  				f7 += 0.3125F;
	  			}
	  			if(!flag2)
	  			{
	  				d4 += 0.01953125D;
	  			}
	  			if(!flag3)
	  			{
	  				f8 -= 0.3125F;
	  			}
	  			if(!flag3)
	  			{
	  				d6 -= 0.01953125D;
	  			}
	  		}
	  		tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f8, d2, d6);
	  		tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f7, d2, d4);
	  		tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f7, d, d4);
	  		tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f8, d, d6);
	  		tessellator.setColorOpaque_F(r, g, b);
	  		tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f8, d2, d6 + 0.0625D);
	  		tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f7, d2, d4 + 0.0625D);
	  		tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f7, d, d4 + 0.0625D);
	  		tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f8, d, d6 + 0.0625D);
	  	} else
	  		if(byte0 == 1)
	  		{
	  			tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f8, d2, d6);
	  			tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f7, d2, d4);
	  			tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f7, d, d4);
	  			tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f8, d, d6);
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f8, d2, d6 + 0.0625D);
	  			tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f7, d2, d4 + 0.0625D);
	  			tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f7, d, d4 + 0.0625D);
	  			tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f8, d, d6 + 0.0625D);
	  		} else
	  			if(byte0 == 2)
	  			{
	  				tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f8, d2, d6);
	  				tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f7, d, d6);
	  				tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f7, d, d4);
	  				tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f8, d2, d4);
	  				tessellator.setColorOpaque_F(r, g, b);
	  				tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f8, d2, d6 + 0.0625D);
	  				tessellator.addVertexWithUV(f6, (float)j + 0.015625F, f7, d, d6 + 0.0625D);
	  				tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f7, d, d4 + 0.0625D);
	  				tessellator.addVertexWithUV(f5, (float)j + 0.015625F, f8, d2, d4 + 0.0625D);
	  			}
	  	if(!blockAccess.isBlockNormalCube(i, j + 1, k))
	  	{
	  		double d1 = (float)(j1 + 16) / 256F;
	  		double d3 = ((float)(j1 + 16) + 15.99F) / 256F;
	  		double d5 = (float)k1 / 256F;
	  		double d7 = ((float)k1 + 15.99F) / 256F;
	  		if(blockAccess.isBlockNormalCube(i - 1, j, k) && (blockAccess.getBlockId(i - 1, j + 1, k) == mod_Inscription.chalkDustRed.blockID ||
	  				blockAccess.getBlockId(i - 1, j + 1, k) == mod_Inscription.chalkDustGold.blockID ||
	  				blockAccess.getBlockId(i - 1, j + 1, k) == mod_Inscription.chalkDustBlue.blockID ||
	  				blockAccess.getBlockId(i - 1, j + 1, k) == mod_Inscription.chalkDustGreen.blockID ||
	  				blockAccess.getBlockId(i - 1, j + 1, k) == mod_Inscription.chalkDustBlack.blockID))
	  		{
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, (float)(j + 1) + 0.021875F, k + 1, d3, d5);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, j + 0, k + 1, d1, d5);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, j + 0, k + 0, d1, d7);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, (float)(j + 1) + 0.021875F, k + 0, d3, d7);
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, (float)(j + 1) + 0.021875F, k + 1, d3, d5 + 0.0625D);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, j + 0, k + 1, d1, d5 + 0.0625D);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, j + 0, k + 0, d1, d7 + 0.0625D);
	  			tessellator.addVertexWithUV((float)i + 0.015625F, (float)(j + 1) + 0.021875F, k + 0, d3, d7 + 0.0625D);
	  		}
	  		if(blockAccess.isBlockNormalCube(i + 1, j, k) && (blockAccess.getBlockId(i + 1, j + 1, k) == mod_Inscription.chalkDustRed.blockID ||
	  				blockAccess.getBlockId(i + 1, j + 1, k) == mod_Inscription.chalkDustGold.blockID ||
	  				blockAccess.getBlockId(i + 1, j + 1, k) == mod_Inscription.chalkDustBlue.blockID ||
	  				blockAccess.getBlockId(i + 1, j + 1, k) == mod_Inscription.chalkDustGreen.blockID ||
	  				blockAccess.getBlockId(i + 1, j + 1, k) == mod_Inscription.chalkDustBlack.blockID))
	  		{
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, j + 0, k + 1, d1, d7);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, (float)(j + 1) + 0.021875F, k + 1, d3, d7);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, (float)(j + 1) + 0.021875F, k + 0, d3, d5);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, j + 0, k + 0, d1, d5);
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, j + 0, k + 1, d1, d7 + 0.0625D);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, (float)(j + 1) + 0.021875F, k + 1, d3, d7 + 0.0625D);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, (float)(j + 1) + 0.021875F, k + 0, d3, d5 + 0.0625D);
	  			tessellator.addVertexWithUV((float)(i + 1) - 0.015625F, j + 0, k + 0, d1, d5 + 0.0625D);
	  		}
	  		if(blockAccess.isBlockNormalCube(i, j, k - 1) && (blockAccess.getBlockId(i, j + 1, k - 1) == mod_Inscription.chalkDustRed.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k - 1) == mod_Inscription.chalkDustGold.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k - 1) == mod_Inscription.chalkDustBlue.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k - 1) == mod_Inscription.chalkDustGreen.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k - 1) == mod_Inscription.chalkDustBlack.blockID))
	  		{
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV(i + 1, j + 0, (float)k + 0.015625F, d1, d7);
	  			tessellator.addVertexWithUV(i + 1, (float)(j + 1) + 0.021875F, (float)k + 0.015625F, d3, d7);
	  			tessellator.addVertexWithUV(i + 0, (float)(j + 1) + 0.021875F, (float)k + 0.015625F, d3, d5);
	  			tessellator.addVertexWithUV(i + 0, j + 0, (float)k + 0.015625F, d1, d5);
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV(i + 1, j + 0, (float)k + 0.015625F, d1, d7 + 0.0625D);
	  			tessellator.addVertexWithUV(i + 1, (float)(j + 1) + 0.021875F, (float)k + 0.015625F, d3, d7 + 0.0625D);
	  			tessellator.addVertexWithUV(i + 0, (float)(j + 1) + 0.021875F, (float)k + 0.015625F, d3, d5 + 0.0625D);
	  			tessellator.addVertexWithUV(i + 0, j + 0, (float)k + 0.015625F, d1, d5 + 0.0625D);
	  		}
	  		if(blockAccess.isBlockNormalCube(i, j, k + 1) && (blockAccess.getBlockId(i, j + 1, k + 1) == mod_Inscription.chalkDustRed.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k + 1) == mod_Inscription.chalkDustGold.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k + 1) == mod_Inscription.chalkDustBlue.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k + 1) == mod_Inscription.chalkDustGreen.blockID ||
	  				blockAccess.getBlockId(i, j + 1, k + 1) == mod_Inscription.chalkDustBlack.blockID))
	  		{
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV(i + 1, (float)(j + 1) + 0.021875F, (float)(k + 1) - 0.015625F, d3, d5);
	  			tessellator.addVertexWithUV(i + 1, j + 0, (float)(k + 1) - 0.015625F, d1, d5);
	  			tessellator.addVertexWithUV(i + 0, j + 0, (float)(k + 1) - 0.015625F, d1, d7);
	  			tessellator.addVertexWithUV(i + 0, (float)(j + 1) + 0.021875F, (float)(k + 1) - 0.015625F, d3, d7);
	  			tessellator.setColorOpaque_F(r, g, b);
	  			tessellator.addVertexWithUV(i + 1, (float)(j + 1) + 0.021875F, (float)(k + 1) - 0.015625F, d3, d5 + 0.0625D);
	  			tessellator.addVertexWithUV(i + 1, j + 0, (float)(k + 1) - 0.015625F, d1, d5 + 0.0625D);
	  			tessellator.addVertexWithUV(i + 0, j + 0, (float)(k + 1) - 0.015625F, d1, d7 + 0.0625D);
	  			tessellator.addVertexWithUV(i + 0, (float)(j + 1) + 0.021875F, (float)(k + 1) - 0.015625F, d3, d7 + 0.0625D);
	  		}
	  	}
	  	return true;
	}
	
	private IBlockAccess blockAccess;
	private int overrideBlockTexture;
	public static boolean fancyGrass = true;
	public boolean field_31088_b;

}
